package state

import (
	"fmt"
	"utilx/logx"
)

type HasItemState struct {
	vendingMachine *VendingMachine
}

func (i *HasItemState) name() string {
	return "HasItemState"
}
func (i *HasItemState) requestItem() error {
	if i.vendingMachine.itemCount == 0 {
		i.vendingMachine.SetCurrentState(i.vendingMachine.noItem)
		return fmt.Errorf("No item present")
	}
	logx.Debug("HasItemState: Item requested")
	i.vendingMachine.SetCurrentState(i.vendingMachine.itemRequested)
	return nil
}

func (i *HasItemState) addItem(count int) error {
	logx.Warnf("HasItemState: %d items added\n", count)
	i.vendingMachine.incrementItemCount(count)
	return nil
}

func (i *HasItemState) insertMoney(money int) error {
	return fmt.Errorf("Please select item first")
}
func (i *HasItemState) dispenseItem(count int) error {
	return fmt.Errorf("Please select item first")
}
